<template>
    <div>
        <a href='/'>返回首页</a>
        <h1>房价录入</h1>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>房型</td>
                    <td>
                        <select v-model="info.RoomFXId">
                            <option value="">请选择</option>
                            <option v-for="a in lisr" :value="a.Id">{{ a.FXName }}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>产品名称</td>
                    <td><input type="text" v-model="info.Name"></td>
                </tr>
                <tr>
                    <td>价格</td>
                    <td><input type="text" v-model="info.Money"></td>
                </tr>
                <tr>
                    <td>收款方式</td>
                    <td><input type="radio" name="str" :value="true" v-model="info.SKFS">预定付费
                        <input type="radio" name="str" :value="false" v-model="info.SKFS">到店付费
                    </td>
                </tr>
                <tr>
                    <td>房间数量</td>
                    <td><input type="text" v-model="info.Number"></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button" value="录入" @click="ok"></td>
                </tr>

            </tbody>

        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import axios from 'axios';
import moment from 'moment';
import { useRouter, useRoute } from 'vue-router';
const router = useRouter();
const route = useRoute();
let info: any = reactive({
    "Id": 0,
    "RoomFXId": "",
    "Name": "",
    "Money": '',
    "SKFS": '',
    "Number": ''
})
let lisr: any = ref([]);
onMounted(() => {
    getlisr();
})
const getlisr = () => {
    axios({
        url: '/api/Type/roomFXes',
        method: 'get'
    })
        .then(res => {
            console.log(res);
            lisr.value = res.data
        })
}


const ok = () => {

    if (info.RoomFXId == "") {
        alert('房型不能为空')
        return;
    }
    if (info.Name == "") {
        alert('产品名称不能为空')
        return;
    }
    if (info.Money == "") {
        alert('价格不能为空')
        return;
    }
    if (info.Number == "") {
        alert('房间数量不能为空')
        return;
    }
    axios({
        url: '/api/Type/TypeAdd',
        method: 'post',
        data: info
    })
        .then(res => {
            if (res.data > 0) {
                alert('录入成功')
                router.push('/typeshou')
                return;
            }
            else {
                alert("录入失败")
                return;
            }

        }).catch(err => {
            console.log(err);

        })
}
</script>

<style scoped></style>